package study.elasticsearch.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import study.elasticsearch.service.EsService;

import java.util.List;
import java.util.Map;

@RequestMapping("/es")
@RestController
public class EsController {
    @Autowired
    EsService esService;
    @RequestMapping("hello")
    public String hello(){

        return "hello elasticsearch!";
    }
    @RequestMapping("parse/{keyword}")
    public Boolean parse(@PathVariable("keyword") String keyword) throws Exception {
        return esService.addContent(keyword);
    }

    @RequestMapping("search/{keyword}/{pageNo}/{pageSize}")
    public List<Map<String,Object>> parse(@PathVariable("keyword") String keyword, @PathVariable("pageNo")int pageNo, @PathVariable("pageSize")int pageSize) throws Exception {
        return esService.search(keyword,pageNo,pageSize);
    }

}
